package sap.feed.java.client;

import java.util.Date;

import org.json.JSONException;
import org.json.JSONObject;

public class SAPFeedLogEntry {
	private long activityTimestamp;
	private String methodName;
	private boolean responseRequired;

	private long responseTimestamp;
	private String responseCode;
	private String responseMessage;
	
	public SAPFeedLogEntry(String methodName, long timestamp, boolean responseRequired){
		this.activityTimestamp = timestamp;
		this.methodName = methodName;
		this.responseRequired = responseRequired;
		this.responseTimestamp = -1;
		this.responseCode = null;
		this.responseMessage = null;
	}
	
	
	public Date getActivityTimestamp(){
		return new Date(activityTimestamp);
	}
	
	public String getMethodName(){
		return methodName;
	}
	
	public boolean getResponseRequired(){
		return responseRequired;
	}
	
	
	public void setResponse(JSONObject response){
		
		try {
			this.responseTimestamp = response.getLong("timestamp");
			this.responseMessage = response.getString("message");
			this.responseCode = response.getString("code");
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	
	public void setResponse(long timestamp, String message, String code){
		this.responseCode = code;
		this.responseMessage = message;
		this.responseTimestamp = timestamp;
	}

	public Date getResponseTimestamp(){
		return new Date(responseTimestamp);
	}
	
	public String getResponseMessage(){
		return responseMessage;
	}
	
	public String getResponseCode(){
		return responseCode;
	}
	
	public String toString(){
		return methodName+"\t"+getActivityTimestamp()+"\t"+responseRequired+"\t"+getResponseTimestamp()+"\t"+responseCode+"\t"+responseMessage;
	}
	
}
